package com.avic.rong.auditcertification.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.avic.rong.BaseActivity;
import com.avic.rong.BuildConfig;
import com.avic.rong.R;
import com.avic.rong.api.UploadPhotoApi;
import com.avic.rong.api.mine.UpdatePictureApi;
import com.avic.rong.auditcertification.api.CertificationMsgApi;
import com.avic.rong.auditcertification.api.CheckUserNameApi;
import com.avic.rong.auditcertification.bean.CertificationMsgBean;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.SDCardUtils;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.ToastTools;
import com.avic.rong.wedgit.HideKeyBroadUtils;
import com.avic.rong.wedgit.StringUtil;
import com.avic.rong.wedgit.customWedgit.SheetDialog;
import com.avic.rong.wedgit.permissionschecker.PermissionChecker;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.example.minato.minastore.utils.CircleProgressDialog;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.orhanobut.logger.Logger;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

import static com.avic.rong.activity.product.OnlineCServiceActivity.recycleBitmap;
import static com.avic.rong.utils.Utils.getContext;


//基本资料
public class ShenFenRzActivity extends BaseActivity {

    private String[] PERMISSIONS = new String[]{
            Manifest.permission.CAMERA,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };
    @BindView(R.id.img_logo)
    ImageView imgLogo;
    @BindView(R.id.rl_header)
    RelativeLayout rlHeader;
    @BindView(R.id.et_user_name)
    EditText etUserName;
    @BindView(R.id.et_field_ly)
    EditText etFieldLy;
    @BindView(R.id.et_desc)
    EditText etDesc;
    @BindView(R.id.et_personalintroduct)
    EditText etPersonalintroduct;
    @BindView(R.id.img_home)
    ImageView imgHome;
    @BindView(R.id.img_upaddhome)
    ImageView imgUpaddhome;
    @BindView(R.id.bt_next)
    Button btNext;
    @BindView(R.id.iv_del)
    ImageView ivDel;
    private SheetDialog sheetDialog;
    private PermissionChecker permissionChecker;

    private int TAKE_CAMERA_PHOTO = 200;
    private String cameraPath;
    private CircleProgressDialog circleProgressDialog;
    private String imgUrl;
    private String loginToken;

    private String LOGO = "logo";
    private String HOMEPAGELOGO = "homepagelogo";

    private String logoPath = "";
    private String homelogoPath = "";

    //判断是传头像还是传主页
    private String flag = "";





    private CertificationMsgBean bean = new CertificationMsgBean();
    private CertificationMsgApi certificationMsgApi;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_shen_fen_rz;
    }

    @Override
    protected void initView() {
        tvTitle.setText("个人认证");
        ivRight.setBackgroundResource(R.mipmap.slh);


        loginToken = SharedPreferencesUtil.getLoginToken();
        circleProgressDialog = new CircleProgressDialog(context);
        permissionChecker = new PermissionChecker(this);



        if (getIntent()!=null){
            CertificationMsgBean data = (CertificationMsgBean) getIntent().getSerializableExtra("data");
            if (data!=null){
                bean = data;
                etUserName.setText(data.getUserName());
                etDesc.setText(data.getUserDesc());
                etFieldLy.setText(data.getMainFields());
                etPersonalintroduct.setText(data.getIntroduction());
                Glide.with(context).applyDefaultRequestOptions(RequestOptions.circleCropTransform().fallback(R.mipmap.deafult_image_header)).load(data.getLogo()).into(imgLogo);
                if (!StringUtil.isEmpty(data.getHomePageLogo())){
                    Glide.with(context).applyDefaultRequestOptions(RequestOptions.fitCenterTransform().fallback(null)).load(data.getHomePageLogo()).into(imgHome);
                    imgUpaddhome.setVisibility(View.GONE);
                    ivDel.setVisibility(View.VISIBLE);
                }
            }
        }

        if (!StringUtil.isEmpty(etUserName.getText().toString().trim())&&!StringUtil.isEmpty(etDesc.getText().toString().trim())){
            btNext.setBackgroundResource(R.mipmap.bg_btlogin);
            btNext.setTextColor(getResources().getColor(R.color.white));
        }else {
            btNext.setBackgroundResource(R.drawable.common_main_r20_grey);
            btNext.setTextColor(getResources().getColor(R.color.black_text));
        }

        TextChange textChange = new TextChange();
        etUserName.addTextChangedListener(textChange);
        etDesc.addTextChangedListener(textChange);

        //获取信息
        certificationMsgApi = new CertificationMsgApi(this, httpOnNextListener);
        certificationMsgApi.setToken(SharedPreferencesUtil.getLoginToken());
        HttpManager.getInstance().doHttpDeal(certificationMsgApi);
    }

    HttpOnNextListener<BaseResultEntity> httpOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            if (!baseResultEntity.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showPublicToast(baseResultEntity.getMsg());
                return;
            }
            CertificationMsgBean data = (CertificationMsgBean) baseResultEntity.getData();
            bean = data;
            etUserName.setText(data.getUserName());
            etDesc.setText(data.getUserDesc());
            etFieldLy.setText(data.getMainFields());
            etPersonalintroduct.setText(data.getIntroduction());
            Glide.with(context).applyDefaultRequestOptions(RequestOptions.circleCropTransform().fallback(R.mipmap.deafult_image_header)).load(data.getLogo()).into(imgLogo);
            if (!StringUtil.isEmpty(data.getHomePageLogo())){
                Glide.with(context).applyDefaultRequestOptions(RequestOptions.fitCenterTransform().fallback(null)).load(data.getHomePageLogo()).into(imgHome);
                imgUpaddhome.setVisibility(View.GONE);
                ivDel.setVisibility(View.VISIBLE);
            }
        }
    };


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        HideKeyBroadUtils.hide(this,ev);
        return super.dispatchTouchEvent(ev);
    }

    // EditText监听器
    class TextChange implements TextWatcher {

        @Override
        public void afterTextChanged(Editable arg0) {
            boolean Sign1 = etUserName.getText().toString().trim().length() > 0;
            boolean Sign2 = etDesc.getText().toString().trim().length() > 0;

            Log.e("ShenFenRzActivity", "Sign1: "+ Sign1+"  Sign2:"+Sign2);

            if (Sign1&&Sign2){
                btNext.setBackgroundResource(R.mipmap.bg_btlogin);
                btNext.setTextColor(getResources().getColor(R.color.white));
            }else{
                btNext.setBackgroundResource(R.drawable.common_main_r20_grey);
                btNext.setTextColor(getResources().getColor(R.color.black_text));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                                      int arg3) {

        }

        @Override
        public void onTextChanged(CharSequence cs, int start, int before,
                                  int count) {

        }

    }


    @Override
    protected void addListener() {
        btNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userName = etUserName.getText().toString().trim();
                String fieldLy = etFieldLy.getText().toString().trim();
                String desc = etDesc.getText().toString().trim();
                String personalIntroduct = etPersonalintroduct.getText().toString().trim();
                if (!StringUtil.isEmpty(userName)&&!StringUtil.isEmpty(desc)) {
                    checkUserName(userName,desc,fieldLy,personalIntroduct);
                }else {
                    if (StringUtil.isEmpty(userName)){
                        ToastTools.showPublicToast("融融号名称不能为空");
                    }else if (StringUtil.isEmpty(desc)){
                        ToastTools.showPublicToast("简介不能为空");
                    }
                }
            }
        });
    }

    private void checkUserName(String userName,String desc, String fieldLy, String personalIntroduct) {
        CheckUserNameApi checkUserNameApi = new CheckUserNameApi(this, new CheckUserNameListener(userName,desc,fieldLy,personalIntroduct));
        checkUserNameApi.setArgument(SharedPreferencesUtil.getLoginToken(),userName);
        HttpManager.getInstance().doHttpDeal(checkUserNameApi);
    }

    public class CheckUserNameListener extends HttpOnNextListener<BaseResultEntity>{

        String userName;
        String desc;
        String fieldLy;
        String personalIntroduct;

        public CheckUserNameListener(String userName, String desc, String fieldLy, String personalIntroduct) {
            this.userName = userName;
            this.desc = desc;
            this.fieldLy = fieldLy;
            this.personalIntroduct = personalIntroduct;
        }

        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            if (!baseResultEntity.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)){
                ToastTools.showPublicToast(baseResultEntity.getMsg());
                return;
            }
            bean.setUserName(userName);
            bean.setMainFields(fieldLy);
            bean.setUserDesc(desc);
            bean.setIntroduction(personalIntroduct);
            if (!StringUtil.isEmpty(logoPath)) {
                bean.setLogo(logoPath);
            }
            if (!StringUtil.isEmpty(homelogoPath)) {
                bean.setHomePageLogo(homelogoPath);
            }
            startActivity(RealInfoActivity.queryIntent(ShenFenRzActivity.this,bean));
        }
    }

    public static Intent queryIntent(Context context) {
        Intent intent = new Intent(context, ShenFenRzActivity.class);
        return intent;
    }

    public static Intent getIntent(Context context,CertificationMsgBean bean) {
        Intent intent = new Intent(context, ShenFenRzActivity.class);
        intent.putExtra("data",bean);
        return intent;
    }


    @OnClick({R.id.rl_header, R.id.img_upaddhome,R.id.img_home,R.id.iv_del})
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.rl_header://头像
                flag = LOGO;
                showFileChooser(LOGO);
                break;
            case R.id.img_upaddhome://主页展示
                flag = HOMEPAGELOGO;
                showFileChooser(HOMEPAGELOGO);
                break;
            case R.id.iv_del://删除主页
                imgUpaddhome.setVisibility(View.VISIBLE);
                ivDel.setVisibility(View.GONE);
                imgHome.setImageDrawable(null);
                break;
        }
    }

    private void showFileChooser(String flag){
        sheetDialog =  new SheetDialog.Builder(this).setTitle(ConstantsUtils.EMPTY_STR)
                .addMenu("拍照", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (sheetDialog != null && sheetDialog.isShowing()){
                            sheetDialog.dismiss();
                        }
                        if (permissionChecker.isLackPermissions(PERMISSIONS)) {
                            permissionChecker.requestPermissions();
                        } else {
                            cameraPath = SDCardUtils.getSDCardPath() + "/temp.png";
                            File file = new File(cameraPath);
                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
                                intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", file));
                            }else{
                                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                            }

                            intent.putExtra("return-data", false);
                            intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
                            intent.putExtra("noFaceDetection", true);
                            startActivityForResult(intent, TAKE_CAMERA_PHOTO);
                        }
                    }
                })
                .addMenu("从相册中选择", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (sheetDialog != null && sheetDialog.isShowing()){
                            sheetDialog.dismiss();
                        }
                        if (permissionChecker.isLackPermissions(PERMISSIONS)) {
                            permissionChecker.requestPermissions();
                        } else {
                            startPickPhoto(flag);
                        }
                    }
                }).setCancelListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        sheetDialog.dismiss();
                    }
                }).create();
        sheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
            }
        });
        sheetDialog.show();
    }

    //选择照片
    private void startPickPhoto(String flag){
        PictureSelector pictureSelector = PictureSelector.create(this);
        if (flag.equals(LOGO)) {
            pictureSelector.openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                    .theme(R.style.picture_default_style)// 主题样式设置 具体参考 values/styles   用法：R.style.picture.white.style
                    .maxSelectNum(1)
                    .minSelectNum(1)// 最小选择数量
                    .imageSpanCount(3)// 每行显示个数
                    .selectionMode(PictureConfig.SINGLE)// 多选 or 单选
                    .previewImage(true)// 是否可预览图片
                    .isCamera(false)// 是否显示拍照按钮
                    .isZoomAnim(false)// 图片列表点击 缩放效果 默认true
                    .enableCrop(true)// 是否裁剪
                    .compress(true)// 是否压缩
                    .circleDimmedLayer(true)
                    .glideOverride(260, 260)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度
                    .hideBottomControls(true)// 是否显示uCrop工具栏，默认不显示
                    .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
                    .showCropFrame(false)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
                    .showCropGrid(false)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
                    .minimumCompressSize(100)// 小于100kb的图片不压缩
                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code`
        }else {
            pictureSelector.openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                    .theme(R.style.picture_default_style)// 主题样式设置 具体参考 values/styles   用法：R.style.picture.white.style
//                    .maxSelectNum(3)
                    .maxSelectNum(1)
                    .minSelectNum(1)// 最小选择数量
                    .imageSpanCount(3)// 每行显示个数
                    .selectionMode(PictureConfig.SINGLE)// 多选 or 单选
                    .previewImage(true)// 是否可预览图片
                    .isCamera(false)// 是否显示拍照按钮
                    .isZoomAnim(false)// 图片列表点击 缩放效果 默认true
                    .compress(true)// 是否压缩
                    .enableCrop(true)
                    .glideOverride(260, 260)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度
                    .hideBottomControls(true)// 是否显示uCrop工具栏，默认不显示
                    .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
                    .showCropFrame(false)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
                    .showCropGrid(false)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
                    .minimumCompressSize(100)// 小于100kb的图片不压缩
                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code`
        }
    }

    //相机相册回传
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            circleProgressDialog.show();
            if (requestCode == TAKE_CAMERA_PHOTO){//拍照
                if (flag.equals(LOGO)) {
                    //upLoad(cameraPath,imgLogo,flag);
                    compressPictureUpload(cameraPath,imgLogo,flag);
                }else {
                    //upLoad(cameraPath,imgHome,flag);
                    compressPictureUpload(cameraPath,imgHome,flag);
                }
            }else if(requestCode == PictureConfig.CHOOSE_REQUEST){//选择照片

                // 图片选择结果回调
                // 例如 LocalMedia 里面返回三种path
                // 1.media.getPath(); 为原图path
                // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true
                // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true
                // 如果裁剪并压缩了，已取压缩路径为准，因为是先裁剪后压缩的
                List<LocalMedia> tempList = PictureSelector.obtainMultipleResult(data);
                for (LocalMedia media : tempList) {
                    if (media.isCompressed()&&media.isCut()) {
                            if (flag.equals(LOGO)) {
                                upLoad(media.getCompressPath(),imgLogo,flag);
                            } else {
                            upLoad(media.getCompressPath(),imgHome,flag);
                        }
                    }
                }
            }
            sheetDialog.cancel();
        }
    }

    //压缩并上传图片
    private Bitmap bitmap;
    private File uploadFile;
    private void compressPictureUpload(String imagePath,ImageView view,String flag){
        circleProgressDialog.show();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 2;
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        options.inPurgeable = true;
        options.inInputShareable = true;
        bitmap = BitmapFactory.decodeFile(imagePath, options);

        Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> emitter) throws Exception {
                uploadFile = compressImage(bitmap);
                emitter.onNext(uploadFile.getAbsolutePath());
            }
        }).subscribeOn(Schedulers.computation()).observeOn(Schedulers.newThread()).subscribe(new Consumer<String>() {
            @Override
            public void accept(String temp) throws Exception {
                upLoad(temp,view,flag);
                recycleBitmap(bitmap);
            }
        });
    }

    /**
     * 压缩图片（质量压缩）
     * @param bitmap
     */
    public static File compressImage(Bitmap bitmap) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);//质量压缩方法，这里100表示不压缩，把压缩后的数据存放到baos中
        int options = 100;
        while (baos.toByteArray().length / 1024 > 5 * 1024 && options > 10) {  //循环判断如果压缩后图片是否大于500kb,大于继续压缩
            baos.reset();//重置baos即清空baos
            options -= 10;//每次都减少10
            Logger.i("-----------------------------option:" + options);
            if (options > 0) {//options 的范围为0--100
                bitmap.compress(Bitmap.CompressFormat.PNG, options, baos);//这里压缩options%，把压缩后的数据存放到baos中
            }
            long length = baos.toByteArray().length;
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date(System.currentTimeMillis());
        String filename = format.format(date);
        File file = new File(Environment.getExternalStorageDirectory(), filename + ".png");
        try {
            FileOutputStream fos = new FileOutputStream(file);
            try {
                fos.write(baos.toByteArray());
                fos.flush();
                fos.close();
            } catch (IOException e) {
                Logger.e(e.getMessage());
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            Logger.e(e.getMessage());
            e.printStackTrace();
        }
        recycleBitmap(bitmap);
        return file;
    }

    /*
     * 上传头像
     * */
    public void upLoad(String photoPath,ImageView view,String flag){
        UploadPhotoApi uploadPhotoApi = new UploadPhotoApi(this,new UploadLogoListener(view,flag) );
        File file = new File(photoPath);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"),file);
        MultipartBody.Part part =  MultipartBody.Part.createFormData("file",file.getName(),requestBody);
        uploadPhotoApi.setPart(part);
        HttpManager.getInstance().doHttpDeal(uploadPhotoApi);
    }

    public class UploadLogoListener extends HttpOnNextListener<BaseResultEntity> {

        ImageView img;
        String flag;
        private RequestOptions apply;

        public UploadLogoListener(ImageView img, String flag) {
            this.img = img;
            this.flag = flag;
        }

        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            if (baseResultEntity.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)){
                imgUrl = (String) baseResultEntity.getData();
                if (flag.equals(LOGO)){
                    upDateLogo(imgUrl);
                    logoPath = imgUrl;
                    apply = new RequestOptions().
                            error(R.mipmap.icon_message_photo).
                            apply(RequestOptions.circleCropTransform()).
                            placeholder(R.mipmap.ic_launcher)
                            .skipMemoryCache(true);
                }else {
                    homelogoPath = imgUrl;
                    apply = new RequestOptions()
                            .apply(RequestOptions.fitCenterTransform())
                            .error(R.mipmap.asd_stan)
                            .placeholder(R.mipmap.ic_launcher)
                            .skipMemoryCache(true);
                }
                Log.e("ShenFenRzActivity", "onNext: "+imgUrl );
                Glide.with(ShenFenRzActivity.this).applyDefaultRequestOptions(apply)
                        .load(imgUrl)
                        .listener(new RequestListener<Drawable>() {
                            @Override
                            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                                circleProgressDialog.dismiss();
                                return false;
                            }

                            @Override
                            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                                img.setImageDrawable(resource);
                                circleProgressDialog.dismiss();
                                ToastTools.showPublicToast("上传成功了");
                                ivDel.setVisibility(View.VISIBLE);
                                imgUpaddhome.setVisibility(View.GONE);
                                return false;
                            }
                        }).into(img);
            }else {
                Toast.makeText(ShenFenRzActivity.this, baseResultEntity.getMsg(), Toast.LENGTH_SHORT).show();
            }
        }
    };

    public void upDateLogo(String imgUrl){
        UpdatePictureApi updatePicture = new UpdatePictureApi(this,new MyUpdatePhotoListener(imgUrl));
        updatePicture.setArgument(loginToken,imgUrl);
        HttpManager.getInstance().doHttpDeal(updatePicture);
    }


    public class MyUpdatePhotoListener extends HttpOnNextListener<BaseResultEntity> {
        String imgPath;

        public MyUpdatePhotoListener(String imgPath) {
            this.imgPath = imgPath;
        }

        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            if (!baseResultEntity.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)){
                ToastTools.showPublicToast(baseResultEntity.getMsg());
            }
            circleProgressDialog.dismiss();
            Log.e("wcx", "imgPath: "+imgPath );
        }
    };

}
